package com.mbyte.easy.rest.maintainapply;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mbyte.easy.maintainapply.entity.Maintainapply;
import com.mbyte.easy.maintainapply.service.IMaintainapplyService;
import com.mbyte.easy.common.controller.BaseController;
import com.mbyte.easy.common.web.AjaxResult;
import com.mbyte.easy.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
* <p>
* 前端控制器
* </p>
* @author lp
* @since 2019-03-11
*/
@RestController
@RequestMapping("rest/maintainapply")
public class RestMaintainapplyController extends BaseController  {

    @Autowired
    private IMaintainapplyService maintainapplyService;

    /**
    * 查询列表
    *
    * @param pageNo
    * @param pageSize
    * @param maintainapply
    * @return
    */
    @RequestMapping
    public AjaxResult index(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String equCreatetimeSpace, Maintainapply maintainapply) {
        Page<Maintainapply> page = new Page<Maintainapply>(pageNo, pageSize);
        QueryWrapper<Maintainapply> queryWrapper = new QueryWrapper<Maintainapply>();

        if(maintainapply.getEquId() != null  && !"".equals(maintainapply.getEquId() + "")) {
            queryWrapper = queryWrapper.like("equ_id",maintainapply.getEquId());
         }


        if(maintainapply.getEquName() != null  && !"".equals(maintainapply.getEquName() + "")) {
            queryWrapper = queryWrapper.like("equ_name",maintainapply.getEquName());
         }


        if(maintainapply.getEquType() != null  && !"".equals(maintainapply.getEquType() + "")) {
            queryWrapper = queryWrapper.like("equ_type",maintainapply.getEquType());
         }


        if(maintainapply.getPorposerId() != null  && !"".equals(maintainapply.getPorposerId() + "")) {
            queryWrapper = queryWrapper.like("porposer_Id",maintainapply.getPorposerId());
         }


        if(maintainapply.getEquCreatetime() != null  && !"".equals(maintainapply.getEquCreatetime() + "")) {
            queryWrapper = queryWrapper.like("equ_createtime",maintainapply.getEquCreatetime());
         }


        if(maintainapply.getStatus() != null  && !"".equals(maintainapply.getStatus() + "")) {
            queryWrapper = queryWrapper.like("status",maintainapply.getStatus());
         }


        if(maintainapply.getFaultCause() != null  && !"".equals(maintainapply.getFaultCause() + "")) {
            queryWrapper = queryWrapper.like("fault_cause",maintainapply.getFaultCause());
         }


        if(maintainapply.getMaintainRemake() != null  && !"".equals(maintainapply.getMaintainRemake() + "")) {
            queryWrapper = queryWrapper.like("maintain_remake",maintainapply.getMaintainRemake());
         }

        IPage<Maintainapply> pageInfo = maintainapplyService.page(page, queryWrapper);

        Map<String, Object> map = new HashMap<>();
        map.put("searchInfo",  maintainapply);
        map.put("pageInfo", new PageInfo(pageInfo));

        return this.success(map);
    }


    /**
    * 添加
    * @param maintainapply
    * @return
    */
    @PostMapping("add")
    public AjaxResult add(Maintainapply maintainapply){
        return toAjax(maintainapplyService.save(maintainapply));
    }

    /**
    * 添加
    * @param maintainapply
    * @return
    */
    @PostMapping("edit")
    public AjaxResult edit(Maintainapply maintainapply){
        return toAjax(maintainapplyService.updateById(maintainapply));
    }
    /**
    * 删除
    * @param id
    * @return
    */
    @GetMapping("delete/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        return toAjax(maintainapplyService.removeById(id));
    }
    /**
    * 批量删除
    * @param ids
    * @return
    */
    @PostMapping("deleteAll")
    public AjaxResult deleteAll(@RequestBody List<Long> ids){
        return toAjax(maintainapplyService.removeByIds(ids));
    }

}

